package com.feri.redromance01.service.impl;

import com.feri.redromance01.dao.AdminDao;
import com.feri.redromance01.entity.Admin;
import com.feri.redromance01.service.intf.AdminService;
import com.feri.redromance01.util.StringUtil;
import com.feri.redromance01.vo.PageBean;
import com.feri.redromance01.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName lcf
 * @Description TODO
 * @Author ASDFGH
 * @Date 2022/8/31 9:41
 * @Version 1.0
 */
@Service
public class AdminServiceImpl implements AdminService {

@Autowired
    private AdminDao dao;

    @Override
    public R save(Admin admin) {
        if (dao.save(admin)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public R update(Admin admin) {
        if (dao.update(admin)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public R delete(int id) {
        if (dao.delete(id)>0){
            return R.ok();

        }else {
            return R.fail();


        }
    }

    @Override
    public PageBean selectPage(String admin_act, int page, int limit) {
        if (StringUtil.isNotEmpty(admin_act)){
            admin_act="%"+admin_act+"%";
        }
        int start=(page-1)*limit;

        return PageBean.ok(dao.selectCount(admin_act),dao.selectPage(admin_act,start,limit));
    }
}
